package com.lzw.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzw.anno.Log;
import com.lzw.pojo.SupplierReturns;
import com.lzw.service.admin.SupplierReturnsManage2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/SupplierReturnsManage2")
public class SupplierReturnsManage2 {

    @Autowired
    private SupplierReturnsManage2Service supplierReturnsManage2Service;

    @GetMapping("/list")
    public PageInfo<SupplierReturns> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate returnDate,
            String medicine, String supplier){
        PageHelper.startPage(pageNum,pageSize);
        List<SupplierReturns> list = supplierReturnsManage2Service.list(pageNum, pageSize, supplier, medicine, returnDate);
        return new PageInfo<>(list);
    }

    @Log
    @PostMapping("/add")
    public String add(@RequestBody SupplierReturns supplierReturns) {
        supplierReturnsManage2Service.add(supplierReturns);
        return "添加成功";
    }

    //更新
    @Log
    @PutMapping("/update")
    public String update(@RequestBody SupplierReturns supplierReturns){
        supplierReturnsManage2Service.update(supplierReturns);
        return "更新成功";
    }
}
